package com.flong.selenium;

import java.io.IOException;
import java.net.URLDecoder;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

/***
 *@Author:liangjilong
 *@Date:2016年1月15日下午3:01:25
 *@Email:jilongliang@sina.com
 *@Version:1.0
 *@CopyRight(c)liangjilong
 *@Description:
 */
public class BaiduImage {
	public static ChromeDriver driver;
	
	public static String urlreq ="";
    static {
        Logger logger = Logger.getLogger("com.gargoylesoftware.htmlunit");
        logger.setLevel(Level.OFF);
        System.setProperty("webdriver.chrome.driver", "D:\\DevSoft\\chromedriver.exe");
    	driver = new ChromeDriver();
    	driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);//SECONDS是秒的意思
        
    }

    public static void main(String[] args) throws IOException, Exception {
    	 
    	
    	urlreq ="http://image.baidu.com/search/index?tn=baiduimage&ipn=r&ct=201326592&cl=2&lm=-1&st=-1&fm=result&fr=&sf=1&fmq=1452918931208_R&pv=&ic=0&nc=1&z=&se=1&showtab=0&fb=0&width=&height=&face=0&istype=2&itg=0&ie=utf-8&word=小清新";
    	
    	
    	// urlreq=URLEncoder.encode(urlreq, "utf-8");
    	
    	urlreq = URLDecoder.decode(urlreq, "utf-8");
    	driver.get(urlreq);
    	
    	 
    	WebElement imgid = driver.findElementById("imgid");
 
    	
    	List<WebElement> imgs=imgid.findElements(By.tagName("img"));//更加li标签去查询html的信息
    	
    	for(WebElement e:imgs){
    		String src = e.getAttribute("src");
    		
    		System.out.println(src);
    	}
    	 
    	 //刷新页面请求
    	// driver.navigate().refresh();
    	//driver.FindElement(By.XPath("//input[@id='submit' and @value='下一步']")).click()；
    	//数据加载完之后，自动关闭浏览器.
    	driver.close();
    	driver.quit();
    	
    }

}
